/**
 * 项目名称: Topic_637.cpp
 * 项目路径: study/DataStructure/LeetCode/树/简单
 * 编辑时间: 2024年08月13日08时13分52秒
 * 用   户: 轻尘
 */

#include <bits/stdc++.h>

using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode() : val(0), left(nullptr), right(nullptr) {}

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    struct node{
        long val;
        int study;
    };
    vector<node>vn;
    vector<double>ans;
    void pre(TreeNode* root,int study){
        if(root){
            study+=1;
            node k{};
            k.val = root->val;
            k.study = study;

            vn.push_back(k);
//            cout<<k.val<<" "<<k.study<<" ";
            pre(root->left,study);
            pre(root->right,study);
        }
    }
    vector<double> averageOfLevels(TreeNode* root) {
        if(!root)return ans;
        else ans.push_back((double )root->val);

        int num[10010];
        long add[10010];
        pre(root,0);
        memset(add,0,sizeof add);
        memset(num,0,sizeof num);

        int max_size = 0;
        for(auto x:vn){
            num[x.study]++;
            add[x.study]+=x.val;
            cout<<x.study<<" "<<x.val<<" "<<num[x.study]<<" "<<add[x.study]<<endl;
            max_size = max(max_size,x.study);
        }

        for(int i =2;i<=max_size;i++){
            ans.push_back((double )add[i]/num[i]);
        }

        return ans;

    }
};

int main() {

    return 0;
}
